package
{
	import as3isolib.display.IsoSprite;
	
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import org.osmf.events.TimeEvent;

	public class Animation extends IsoSprite
	{
		public var pics:Array = new Array();
		private var pos:int = 0;
		private var wx:int,hy:int;
		private var t:int = 20;
		public function Animation()
		{
			super();
			
		}
		public function overrideSize(x:int,y:int){
			wx=x;
			hy=y;
		}
		public function initiate(st:String,c:int):void{
			for (var i:int = 0;i<=c;i++){
				var image:ImageSprite = new ImageSprite();
				image.overrideSize(wx,hy);
				image.load(null,"assets/images/Animations/"+st+"/"+st+"_"+i+".png");
				pics.push(image);
			}
		}
		public function coeff(n:int):void{
			t=n;
		}
		public function run(){
			var timer:Timer = new Timer(1000/t);
			timer.addEventListener(TimerEvent.TIMER,tick);
			timer.start();
		}
		private function tick(e:Event):void{
			if (pics[pos] == null || (pics[pos] as ImageSprite).bitmap==null)return;
			pos+=1; 
			pos%=pics.length;
			sprites=[(pics[pos] as ImageSprite).bitmap];
		}
		
		public function setSprite(i:int = 0):void{
			sprites=[(pics[i] as ImageSprite).bitmap];
		}
		
	}
	
}